package com.cl.spark.dto;

import com.alibaba.fastjson.JSONArray;
import lombok.Data;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;

import java.util.List;

@Data
public class SparkResult {
    private Dataset<Row> dataset;
    private String tableName;
    private Long count;
    private String msg;
    private Integer code;
    private Integer positionLeft;
    private Boolean fieldAppendTableNameFlag = false;
    public static SparkResult success(Dataset<Row> dataset) {
        SparkResult sparkResult = new SparkResult();
        sparkResult.setDataset(dataset);
        sparkResult.setCount(dataset.count());
        sparkResult.setCode(200);
        return sparkResult;
    }

    public static SparkResult success(Dataset<Row> dataset, Long count) {
        SparkResult sparkResult = new SparkResult();
        sparkResult.setDataset(dataset);
        sparkResult.setCount(count);
        sparkResult.setCode(200);
        return sparkResult;
    }

    public static SparkResult success(Dataset<Row> dataset, String tableName) {
        SparkResult sparkResult = new SparkResult();
        sparkResult.setDataset(dataset);
        sparkResult.setCount(dataset.count());
        sparkResult.setTableName(tableName);
        sparkResult.setCode(200);
        return sparkResult;
    }


    public static SparkResult failed(String msg) {
        SparkResult sparkResult = new SparkResult();
        sparkResult.setMsg(msg);
        sparkResult.setCode(500);
        return sparkResult;
    }

    public Integer getPositionLeft() {
        if (positionLeft == null) {
            return 0;
        }
        return positionLeft;
    }

//    public static SparkResult success(String hdfsPath,Integer total) {
//        SparkResult sparkResult = new SparkResult();
//        sparkResult.setHdfsPath(hdfsPath);
//        sparkResult.setTotal(total);
//        sparkResult.setCode(200);
//        return sparkResult;
//    }
//    public static SparkResult success(String hdfsPath,Integer total,String msg) {
//        SparkResult sparkResult = new SparkResult();
//        sparkResult.setHdfsPath(hdfsPath);
//        sparkResult.setTotal(total);
//        sparkResult.setMsg(msg);
//        sparkResult.setCode(200);
//        return sparkResult;
//    }

}
